#include<iostream>
#include<queue>
using namespace std;
int main()
{
	int m,i=0,j,n,k;
	int s;
	queue<int>q;
	for(j=1;j<=m;j++)
	{
		q.push(j);
	}
	while(q.size()!=1)
	{
		
			if(k%n!=0)
			s=q.top();
			q.push(s);
			else if(k%n==0)
			q.pop();
			k++;
	}
	cout<<q.top();
	return 0;

}
